﻿using fabao.Common;
using fabao.Common.Util;
using Fabao.Shared.Domain;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Member.Domain.Entities
{
    public class AdminUser:AggregateRootEntity
    {
        public string username { get; set; }
        public string password { get; set; }
        public string phone { get; set; }
        [SugarColumn(ColumnName = "role_id")]
        public int roleId { get; set; }
        public DateTime createTime { get; set; }

        /// <summary>
        /// 是否为超级管理员登录
        /// </summary>
        /// <param name="loginname"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool isSuperAdmin(string phone, string password)
        {
            string spcyadmin = ConfigSettings.GetConfig("SuperAdminLogin");
            string spcyadminPwd = ConfigSettings.GetConfig("SuperAdminPwd");
            if (phone == spcyadmin && password == spcyadminPwd)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 初始化超级管理员
        /// </summary>
        /// <param name="loginname"></param>
        public void CreateSuperAdmin(string phone)
        {
            this.id = 0;
            this.username = "超级管理员";
            this.phone = phone;
            this.roleId = 0;
        }
        /// <summary>
        /// 密码转md5
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public void SetMd5Pwd(string password)
        {
            this.password = MD5Helper.Md5(password);
        }
    }
}
